/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControllerBeans;

import Classes.Base64;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.FileUploadEvent;

/**
 *
 * @author xiph
 */
@ManagedBean
@SessionScoped
public class FileUploadController implements Serializable
{
	private String encodedFile = "";

	/** Creates a new instance of FileUploadController */
	public FileUploadController() {
	}

	public String getEncodedFile() {
		return encodedFile;
	}

	public void setEncodedFile(String encodedFile) {
		this.encodedFile = encodedFile;
	}

	public void handleFileUpload(FileUploadEvent event)
	{
		FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
		FacesContext.getCurrentInstance().addMessage(null, msg);
		encodedFile = Base64.encodeBytes(event.getFile().getContents());
	}
}
